﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.Web.coffinegurunaru.AppLogic.Page;
using Com.Library.DB.Board;
using Com.Library.Page;
using System.Web.Script.Serialization;

namespace Com.Web.coffinegurunaru.manager.board
{
	public partial class boardMethod : ManagerAjaxPage
	{
		public void CreateBoard(byte BoardSN, string BoardName, string JsonData)
		{
			BoardModel.Create(BoardSN, BoardName, JsonData);
		}

		public string[] GetListBoard(int PageNo, byte PageSize)
		{
			int CntTotal = 0;
			List<BoardEntity> list = BoardModel.GetList(PageNo, PageSize, out CntTotal);

			Dictionary<string, object> properties = new Dictionary<string,object>()
			{
				{"List", list}
			};

			string[] retVal = new string[10];

			retVal[0] = ViewManager<board>.Render("/manager/board/boardlist.ascx", properties);
			retVal[1] = CntTotal.ToString();

			return retVal;
		}

		public void ModifyBoard(byte BoardSN, string BoardName, string JsonData)
		{
			BoardModel.Modify(BoardSN, BoardName, JsonData);
		}

		public void RemoveBoard(byte BoardSN)
		{
			BoardModel.Remove(BoardSN);
		}

        public string CreateArticle(byte BoardSN, string Title, string Content, string JsonData, string FileUrl)
        {
            int articleSN = ArticleModel.Create(BoardSN, Title, Content, JsonData, WebCookies.ManagerSN, string.Empty, FileUrl);
            return articleSN.ToString();
        }

        public string[] GetListArticle(byte BoardSN, int PageNo, byte PageSize, string Title_Search)
        {
            int cntTotal = 0;

            List<ArticleEntity> articles = ArticleModel.GetList(BoardSN, Title_Search, PageNo, PageSize, out cntTotal);

            Dictionary<string, object> properties = new Dictionary<string, object>()
            {
                {"List", articles}
            };

            string[] retVal = new string[] 
            {
                ViewManager<article>.Render("/manager/board/articlelist.ascx", properties),
                cntTotal.ToString()
            };

            return retVal;
        }

        public string GetInfoArticle(int ArticleSN)
        {
            ArticleEntity article = ArticleModel.GetInfo(ArticleSN, false, null);

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            string retVal = serializer.Serialize(new {
                n1BoardSN = article.n1BoardSN,
                n4ArticleSN = article.n4ArticleSN,
                strTitle = article.strTitle,
                strContent = article.strContent,
				strJsonData = article.strJsonData,
                strFileUrl = article.strFileUrl,
                n4ManagerSNWriter = article.n4ManagerSNWriter
            });

            return retVal;
        }

        public void ModifyArticle(int ArticleSN, string Title, string Content, string JsonData, string FileUrl)
        {
            ArticleModel.Modify(ArticleSN, Title, Content, JsonData, FileUrl);
        }

        public void RemoveArticle(int ArticleSN)
        {
            ArticleModel.Remove(ArticleSN);
        }
	}
}
